package com.intel.two.controller.older;

import com.intel.two.common.R;
import com.intel.two.common.older.LayuiPageVo;
import com.intel.two.pojo.older.People;
import com.intel.two.pojo.older.Suite;
import com.intel.two.service.older.SuiteService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("suite")
public class SuiteController {
    @Autowired
    private SuiteService suiteService;

    @RequestMapping("suitelist")
    public LayuiPageVo<Suite> suitePageData(@RequestParam Map<String, Object> params) {
        // 注意 这里使用 map来接受参数  前端传的不定参数 都可以封装到 map 中

        return suiteService.suitePageData(params);

    }

    @RequestMapping("add")
    public R addSuite(Suite suite) {
        int result = suiteService.addSuite(suite);
        if (result == 1) {
            return R.ok();
        } else
            return R.error();
    }

    @RequestMapping("/delete")
    public R deleteById(Integer id) {
        int result = suiteService.deleteById(id);
        if (result == 1) {
            return R.ok();
        } else
            return R.error();
    }

    @GetMapping("/deleteAll")
    public R deleteAll(@RequestParam Map<String, Object> map) {
        int result = suiteService.deleteAll(map);

        if (result == 1) {
            return R.ok();
        } else {
            return R.error();
        }
    }
    @RequestMapping("update")
    public R updateSuite(Suite suite){
        System.out.println(suite);
        int result = suiteService.udateSuite(suite);

        return result==1 ? R.ok():R.error();

    }
}
